<?php
ArrowController::importModel("org.arrowplatform.controls.presentation.table.filters.ArrowTableAbstractFilter");
class ArrowTableRangeFilter extends ArrowAbstractTableFilter{
	
	public function configure(){
		parent::configure();
	}
	
	public function generateFilter($value){
		if($value)
			$tmp = explode("_arrow_range_", $value);
		else 
			$tmp = array("0", "0");
		
		$str = 'Od: <input type="text" field="'.$this->getField().'" value="'.$tmp[0].'"   /><br />';
		$str.= 'Do: <input type="text" field="'.$this->getField().'" value="'.$tmp[1].'"   /><br />';
		$str.= '<div class="ctrl-popup-cancel"></div>';
		$str.= '<div class="ctrl-popup-submit"></div>';
		return $str;
	}
	
	public function generateSetFilterValues($value) {
		
		$str = '';
		$registry = self::$registry[$this->tableId];
			
		// wygeneruj 2 różne linki 
		$tmp = explode("_arrow_range_", $value);
		$copy = $registry[$this->field];
		
		if($tmp[1] != '0')
			$registry[$this->field]['value'] = "_arrow_range_{$tmp[1]}";
		else
			unset($registry[$this->field]);
		
		$downResetReg = base64_encode(json_encode($registry));
		$downResetLink = ArrowCtrlStateManager::getDefault()->getStateChangeLink($this->table, array( "filtersRegistry" => $downResetReg ));
		
		$registry[$this->field] = $copy;
		
		if($tmp[0] != '0')
			$registry[$this->field]['value'] = "{$tmp[0]}_arrow_range_";
		else
			unset($registry[$this->field]);
		
		$upResetReg = base64_encode(json_encode($registry));
		$upResetLink = ArrowCtrlStateManager::getDefault()->getStateChangeLink($this->table, array( "filtersRegistry" => $upResetReg ));
		
		// wygeneruj pola
		if(isset($tmp[0]) && $tmp[0] != '' && $tmp[0] != '_arrow_range_')
			$str .= "<div><div style=\"margin-left: 10px;\">od</div><div class=\"ctrl-table-set-filter-value\" >{$tmp[0]}</div><a rel=\"$downResetReg\" href=\"$downResetLink\" ></a></div> ";
		
		if(isset($tmp[1]) && $tmp[1] != '')
			$str .= "<div><div style=\"margin-left: 10px;\">do</div><div class=\"ctrl-table-set-filter-value\" >{$tmp[1]}</div><a rel=\"$upResetReg\" href=\"$upResetLink\" ></a></div>";
		
		return $str;
	}
}
?>